# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html


class ZhilianjobsPipeline(object):
    def open_spider(self, spider):
        self.data_fp = open("./data.csv", "w")
        import csv
        self.csv_writer = csv.DictWriter(self.data_fp, fieldnames=("work_experience", "salary_range"))
        self.csv_writer.writeheader()

    def process_item(self, item, spider):
        self.csv_writer.writerow({"work_experience": item["work_experience"], "salary_range": item["salary_range"]})
        return item

    def close_spider(self, spider):
        self.data_fp.close()
